

public class Ex6_2 {
	public Ex6_2() {}
	public static void main(String[] args) {		
		Integer m = 12;
		Integer n = 5;
		Integer[][] down = Utils.readMatrix("C:\\Users\\josemfer\\Downloads\\down.txt");
		Integer[][] right = Utils.readMatrix("C:\\Users\\josemfer\\Downloads\\right.txt");
		Integer[][] s = new Integer[n+1][m+1];
		s[0][0] = 0;		
		for (int i=1;i<=n;i++) {
			s[i][0] = s[i-1][0] + down[i-1][0]; 
		}
		for (int j=1;j<=m;j++) {
			s[0][j] = s[0][j-1] + right[0][j-1];
		}
		for (int i=1;i<=n;i++) {
			for (int j=1;j<=m;j++) {
				Integer rightVal = s[i][j-1] + right[i][j-1];
				Integer downVal = s[i-1][j] + down[i-1][j];
				if (rightVal > downVal) {
					s[i][j] = rightVal;
				} else {
					s[i][j] = downVal;
				}
			}
		}
		System.out.println(s[n][m]);		
	}		
}